<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>登录</title>
    <link rel="stylesheet" href="../../static/layui/css/layui.css">
</head>
<body >
<div style="display: flex;width: 100%;height: 100vh;justify-content: center;align-items: center;flex-direction: column">

    <fieldset class="layui-elem-field layui-field-title"    >
        <legend>登录有礼</legend>
    </fieldset>
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-block">
                <input id="username" style="width: 500px" type="text" name="title" required lay-verify="required"
                       placeholder="请输入用户名" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-block">
                <input id="password" style="width: 500px" type="password" name="password" required lay-verify="required"
                       placeholder="请输入密码" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button onclick="add()" class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<script src="../../static/layui/layui.js"></script>
<script src="../../static/layui/jquery-3.4.1.js"></script>
<script>
    function add() {
        var name = $("#username").val()
        var pass = $("#password").val()

        if (name == "" || pass == "") {
            alert("信息不完整");
            return
        }

        $.ajax({
                url: "{:url('login/login')}",
                data: {username: name, password: pass},
                success: function (data) {
                    if (data.code == 1) {
                        // alert("登录成功！");
                        window.location.href="{:url('Index/index')}"
                    } else {
                        alert("用户名或密码错误！");
                    }
                }
            }
        )
    }
</script>
{block name="js"}{/block}
</body>
</html>